package cn.dsttl3.tupan.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class AppUtils {
    /*
    百度应用信息
     */
    String YOUR_CLIENT_ID = "FQRIB3318HX4q3eZDQw1brRe9omxCpvq";
    String YOUR_REGISTERED_REDIRECT_URI = "https://dsttl3.cn/baiduapi.html";
    String YOUR_CLIENT_SECRET = "n7pels13MGeBPKBzDC9XNAsGKrNpWqMA";

    /**
     * @return 移动端登录授权链接
     */

    public String getLoginUrl(){

        String url = "https://openapi.baidu.com/oauth/2.0/authorize?response_type=code" +
                "&client_id=" +YOUR_CLIENT_ID +
                "&redirect_uri=" + YOUR_REGISTERED_REDIRECT_URI +
                "&scope=basic,netdisk&force_login=0";
        try {
            url = URLEncoder.encode(url,"UTF-8");
            url = "https://wappass.baidu.com/passport/?login&tpl=wimn&sms=1&regtype=1&u=" +
                    url +
                    "&extrajson=%7b%22src%22%3a%22se_000000%22%7d#/password_login";
            return url;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * @return Access_token授权链接
     */

    public String getAccessTokenUrl(String CODE){
        return "https://openapi.baidu.com/oauth/2.0/token?grant_type=authorization_code" +
                "&code=" + CODE +
                "&client_id=" + YOUR_CLIENT_ID +
                "&client_secret=" + YOUR_CLIENT_SECRET +
                "&redirect_uri=" + YOUR_REGISTERED_REDIRECT_URI;
    }

}
